<?php
class SimpleTabBox{
	var $id ;
	var $name ;
	var $menus = array();
	var $freeHtmls ;
	var $focusTabId ;
	var $url ;

	function SimpleTabBox($id,$focusTabId){
		$this->boxid = $id ;
		if($this->boxid == ""){
			$this->boxid = "ttbox";
		}
		$this->focusTabId = $focusTabId ;
	}

	function addMenu($id,$name,$url){
		$menu = new Menu($id,$name,$url);
		array_push($this->menus,$menu);
	}

	function checkFocus(){
		if(!isset($this->focusTabId) || $this->focusTabId == ""){
			if(count($this->menus) > 0){
				$this->focusTabId = $this->menus[0]->id ;
			}
		}
		for($i=0;$i<count($this->menus);$i++){
			$menu = $this->menus[$i] ;
			$menu->focus = $menu->id == $this->focusTabId ;
		}
	}

	function showHtmlHead(){
		echo $this->getHtmlHead();
	}
	
	function showHtmlFoot(){
		echo $this->getHtmlFoot();
	}

	function getHtmlHead(){
		$this->checkFocus();
	
		$crlf = "\r\n";
		$tab = "\t";
		
		$html  = "";
		$html .= "<div id='sipmletab'>";
		$html .= "<table id='".$this->boxid."' class='simpletabletab' cellpadding='0' cellspacing='0'> $crlf";
		$html .= "<tr> $crlf";
		$html .= "	<td class='simplcoltab sthead'></td> $crlf";

		$src = '' ;

		for($i=0;$i<count($this->menus);$i++){
			$menu = $this->menus[$i] ;
			if($i > 0){
				$html .= "<td class='simplcoltab stsplit'></td> $crlf";
			}
			if($menu->getFocus()){
				$src = $menu->url;
				$this->url = $menu->url ;

				$html .= "<td id='".$this->boxid."_col_".$i."' class='simplcoltab stfocus' url='".$menu->url."' onclick=\"clickSimpleTab(this,'".$this->boxid."')\"> $crlf";
				$html .= "	<div id='".$this->boxid."_div_".$i."' class='simpldivtab stfocus'>".$menu->name."</div> $crlf";
				$html .= "</td> $crlf";
			}else{
				$html .= "<td id='".$this->boxid."_col_".$i."' class='simplcoltab stdark' url='".$menu->url."' onclick=\"clickSimpleTab(this,'".$this->boxid."')\"> $crlf";
				$html .= "	<div id='".$this->boxid."_div_".$i."' class='simpldivtab stdark'>".$menu->name."</div> $crlf";
				$html .= "</td> $crlf";
			}
		}

		$html .= "	<td class='simplcoltab stend'>".(($this->freeHtmls == null) ? "" : $this->freeHtmls)."</td> $crlf";
		$html .= "</tr> $crlf";
		$html .= "<tr> $crlf";
		$html .= "	<td class='simplcoltab stmain' colspan='".(count($this->menus)*2+1)."'> $crlf";
		$html .= "		<div class='simplecoltab_innerdiv'> $crlf";
		$html .= "$crlf";
		
		return $html;
	}

	function getHtmlFoot(){
	
		$crlf = "\r\n";
		$tab = "\t";
		
		$html  = "";
		$html .= "		</div> $crlf";
		$html .= "	</td> $crlf";
		$html .= "</tr> $crlf";
		$html .= "</table> $crlf";
		$html .= "</div> $crlf";
		
		return $html;
	}
	
	function getUrl(){
		return $this->url ;
	}

	
}
?>